<?php
class ModelModuleProMegamenu extends Model {
	
	public function listSubWithoutUl($parent_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "pro_megamenu  WHERE " . DB_PREFIX . "pro_megamenu.parent_id = '".$parent_id."' ORDER BY " . DB_PREFIX . "pro_megamenu.id ASC");
		$result=array();
		foreach ($query->rows as $value) {
			$result[] = $value;
		}
		if($result){
			foreach($result as $key=> $value) : 				
				if($value['type']=='category')
					$value['url'] = $this->url->link('product/category', 'path=' . $value['type_id']);
				if($value['type']=='infomation')
					$value['url'] = $this->url->link('information/information', 'information_id=' . $value['type_id']);
				if($value['type']=='manufacturer')
					$value['url'] = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $value['type_id']);
					?>
					<li><a href="<?php echo $value['url']; ?>"><?php echo $value['title'];?></a></li>
					<?php
					$this->listSubWithoutUl($value['id']);
			endforeach ;
		}
	}
	public function list_submenu_mega($parent_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "pro_megamenu  WHERE " . DB_PREFIX . "pro_megamenu.id = '".$parent_id."'");
		$result=array();
		foreach ($query->rows as $value) {
			$result[] = $value;
		}
		$parent_info = $result;
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "pro_megamenu  WHERE " . DB_PREFIX . "pro_megamenu.parent_id = '".$parent_id."' ORDER BY " . DB_PREFIX . "pro_megamenu.id ASC");
		$result=array();
		foreach ($query->rows as $value) {
			$result[] = $value;
		}
		?>
			<div class="sub-menu megamenu-sub columns<?php echo $parent_info[0]['columns'] ?>" style="width:<?php echo $parent_info[0]['widths']; ?>px">
					<div class='mega-content'>
						<?php echo $parent_info[0]['subcontent'] ; ?>
					</div>
					<?php
					if($result!=null){
					echo "<ul class='sub-menu-mega'>";
						foreach($result as $key=> $value) : ?>					
							<?php
							if($value['type']=='category')
								$value['url'] = $this->url->link('product/category', 'path=' . $value['type_id']);
							if($value['type']=='infomation')
								$value['url'] = $this->url->link('information/information', 'information_id=' . $value['type_id']);
							if($value['type']=='manufacturer')
								$value['url'] = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $value['type_id']);
							?>
							<li><a href="<?php echo $value['url']; ?>"><?php echo $value['title'];?></a></li>
							<?php $this->listSubWithoutUl($value['id']);?>
						<?php 
						endforeach ;
					echo "</ul>";
					}
					?>
			</div>
		<?php
	}
	public function list_submenu($parent_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "pro_megamenu  WHERE " . DB_PREFIX . "pro_megamenu.parent_id = '".$parent_id."' ORDER BY " . DB_PREFIX . "pro_megamenu.id ASC");
		$result=array();
		foreach ($query->rows as $value) {
			$result[] = $value;
		}
		if($result) {
		?>
			<div class="sub-menu">
				<ul>
					<?php foreach($result as $key=>$value) : ?>						
						<?php
							if($value['type']=='category')
								$value['url'] = $this->url->link('product/category', 'path=' . $value['type_id']);
							if($value['type']=='infomation')
								$value['url'] = $this->url->link('information/information', 'information_id=' . $value['type_id']);
							if($value['type']=='manufacturer')
								$value['url'] = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $value['type_id']);
							?>
						<li>
							<a href="<?php echo $value['url']; ?>"><?php echo $value['title'];?></a>
							<?php $this->list_submenu($value['id']); ?>
						</li>
					<?php endforeach ; ?>
				</ul>	
			</div>	
		<?php
		}	
	}
	public function getlist() {

      $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "pro_megamenu  WHERE " . DB_PREFIX . "pro_megamenu.parent_id = '0' ORDER BY " . DB_PREFIX . "pro_megamenu.id ASC");
	  $result=array();
	  foreach ($query->rows as $value) {
				$result[] = $value;
	  }	
	  return $result;		
	}
}
?>